﻿using JustMetClient.Commons;
using Azylee.Core.AppUtils;
using Azylee.Core.DataUtils.DateTimeUtils;
using Azylee.Core.DataUtils.UnitConvertUtils;
using Azylee.Core.WindowsUtils.InfoUtils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using ZXing;
using ZXing.QrCode;

namespace JustMetClient.Modules.QrcodeModule
{
    public class ClientInfoQrcode
    {
        public static bool Simple(out Bitmap bmp)
        {
            string split = "，";
            bmp = null;
            try
            {
                BarcodeWriter writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE;
                QrCodeEncodingOptions options = new QrCodeEncodingOptions();
                options.DisableECI = true;
                //设置内容编码
                options.CharacterSet = "UTF-8";
                //设置二维码的宽度和高度
                options.Width = 500;
                options.Height = 500;
                //设置二维码的边距,单位不是固定像素
                options.Margin = 1;
                writer.Options = options;
                //拼接内容
                StringBuilder sb = new StringBuilder();
                sb.Append($"姓名：{ R.UserName}");
                sb.Append(split);
                sb.Append($"账号：{R.Account}");
                sb.Append(split);
                sb.Append($"IP：{R.NetInfo.IP}");
                sb.Append(split);
                sb.Append($"MAC：{R.NetInfo.Mac}");
                sb.Append(split);
                sb.Append($"网关：{R.NetInfo.Gateway}");
                sb.Append(split);
                sb.Append($"策略组：{R.StrategyGroup}");
                sb.Append(split);
                sb.Append($"版本号：{R.Version}");
                sb.Append(split);
                sb.Append($"通信正常：{(R.Socket.IsConnect ? "是" : "否")}");
                sb.Append(split);
                sb.Append($"开机时间：{DateTimeConvert.StandardString(R.PowerTime)}");
                sb.Append(split);
                sb.Append($"启动时间：{DateTimeConvert.StandardString(R.StartTime)}");
                sb.Append(split);
                sb.Append($"系统：{OSInfoTool.Caption()} {(Environment.Is64BitOperatingSystem ? "64" : "32")}位");
                sb.Append(split);
                sb.Append($"总内存：{Math.Round((double)ComputerInfoTool.TotalPhysicalMemory() / 1024 / 1024, 2)} GB");
                sb.Append(split);
                sb.Append($"可用内存：{Math.Round((double)ComputerInfoTool.AvailablePhysicalMemory() / 1024 / 1024, 2)} GB");
                sb.Append(split);
                sb.Append($"总系统盘：{Math.Round((double)ComputerInfoTool.GetSystemDriveTotalSize() / 1024 / 1024, 2)} GB");
                sb.Append(split);
                sb.Append($"可用系统盘：{Math.Round((double)ComputerInfoTool.GetSystemDriveAvailableSize() / 1024 / 1024, 2)} GB");
                sb.Append(split);
                sb.Append($"程序占磁盘：{ByteConvertTool.Cvt(R.AppSize, "MB")} MB");
                sb.Append(split);
                sb.Append($"程序占内存：{ByteConvertTool.Cvt(AppInfoTool.RAM() * 1024, "MB")} MB");
                //输出图形
                bmp = writer.Write(sb.ToString());
                return true;
            }
            catch { return false; }
        }
    }
}
